from PyQt4.QtCore import *
from PyQt4.QtGui import *

from core import cmds

class PyMimeData(QMimeData):

    def __init__(self, data=None):
        QMimeData.__init__(self)
        if data is not None:
            self.set_data(data)

    def set_data(self, node):
        if cmds.is_type(node):
            self.setText("Type:" + node.__name__)
        elif cmds.is_component(node):
            self.setText(node.__class__.__name__ + ":" + node.name)
        else:
            self.setText(node)
        
    def get_data(self):
        text = str(self.text())
        if ":" in text:
            parts = text.split(':')
            if len(parts) == 2:
                return cmds.get(*parts)
        return text